<?php

	function action(){
	}
	
	function saveLine($date, $descr, $sum, $comment, $category, $type, $selectedCategory){
		$smetki = new Tsmetki(con());
		if(strcasecmp("описание",$descr) == 0){
			$descr = "";
 		}
		if(strcasecmp("допълнителен коментар",$comment) == 0){
			$comment = "";
		}
		$smetki->add($date, $descr, $sum, $comment, $category, $type);
		return getEntriesByDate($selectedCategory);
	}
	
	function removeLine($id, $selectedCategory){
		$smetki = new Tsmetki(con());
		$smetki->remove($id);
		return getEntriesByDate($selectedCategory);
 	}

	function getSmetki(){
		$smetki = new Tsmetki(con());
		return $smetki->getAll();
	}
	
	
	function rencode($array){
		$result = array();
		for ($number = 0; $number < count($array); $number++){
			$index = $array[$number][0];
			$result[$index] = $array[$number][1];
		}
		return $result;
	}
	
	
	function getLastEntriesByDate(){
		$smetki = new Tsmetki(con());
		$listCategories = $smetki->getEntries();
		if (isset($listCategories[0][0])){
			$_SESSION['selSmetkiCateg'] = $listCategories[0][0];
			$result = $smetki->getByMonthEntries($listCategories[0][0]);
		} else {
			$result = array();
		}
		return $result;
	}
	
	function getCat(){
		return $_SESSION['selSmetkiCateg'];
	}
	
	function refreshSmetki(){
		return getEntriesByDate($_SESSION['selSmetkiCateg']);
	}
	
	function getEntriesByDate($cats){
		$smetki = new Tsmetki(con());
		$_SESSION['selSmetkiCateg'] = $cats;
		if (strcasecmp("ВСИЧКИ",$cats) == 0){
			$result = $smetki->getAll();
		} else {
			$result = $smetki->getByMonthEntries($cats);	
		}
		
		return $result;
	}
					

?>